package cn.wolfcode.trip.base.service.impl;


import cn.wolfcode.trip.base.domain.Information;
import cn.wolfcode.trip.base.domain.TravelComment;
import cn.wolfcode.trip.base.mapper.InformationMapper;
import cn.wolfcode.trip.base.mapper.TravelCommentMapper;
import cn.wolfcode.trip.base.query.TravelCommentQuery;
import cn.wolfcode.trip.base.service.ITravelCommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TravelCommentServiceImpl implements ITravelCommentService {
    @Autowired
    private TravelCommentMapper travelCommentMapper;
    @Autowired
    private InformationMapper informationMapper;


    @Override
    public void save(TravelComment travelComment) {
            //评论保存时系统自动提供创建时间
            Date date = new Date();
            travelComment.setCreateTime(date);
            travelCommentMapper.insert(travelComment);
            //产生消息
            //保存关系
            informationMapper.insertRelation(travelComment.getId(),1);
            //保存消息

        try {
            informationMapper.insert(new Information(travelComment.getUser(),travelComment.getAuthor(),1,date));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public PageInfo<TravelComment> query(TravelCommentQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<TravelComment> list=travelCommentMapper.queryForList(qo);
        return new PageInfo<>(list);
    }

   /* @Override
    public List queryComments(Long userId) {
        List travelcomments=travelCommentMapper.queryComments(userId);
        return travelcomments;
    }
*/

}
